package com.kun.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kun.dao.WorkInfoDao;
import com.kun.entity.UserInfo;
import com.kun.entity.WorkInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class WorkInfoService {
    @Autowired
    private WorkInfoDao workInfoDao;
    public WorkInfo findById(Integer workId) { return workInfoDao.selectByPrimaryKey(workId); }
    public Map<String, Object> selectByPage(Integer pageNum, Integer pageSize, WorkInfo workInfo) {
        //通过PageHelper对象设定分页参数
        PageHelper.startPage(pageNum, pageSize);
        //当前页面的数据
        List<WorkInfo> list = workInfoDao.findAll(workInfo);
        //创建PageInfo对象，并将当前页面数据传入，计算分页相关数据
        PageInfo<WorkInfo> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        Map<String, Object> map = new HashMap<>();
        map.put("list", list);
        map.put("total", total);
        return map;
    }
    public int insertWork(WorkInfo workInfo) {
        return workInfoDao.insert(workInfo);
    }
    public List<WorkInfo> findWork(){
        return workInfoDao.findWork();
    }
    public int deleteWork(Integer[] workIds){return  workInfoDao.batchDelete(workIds);}
    public int updateWork(WorkInfo workInfo){
        return workInfoDao.updateByPrimaryKeySelective(workInfo);
    }
}
